--[[对coronaApi重写
]]
local M = {}

local function changeParent(obj, parent, superGroup)
	-- 是否为display对象
	if not coreDisplay.isDisplayObj(obj) then
		return obj
	end

	-- 已经传入了父组
	if coreDisplay.isGroup(parent) then

	else
		if type(parent) == "table" then
			if coreDisplay.isGroup(parent[1]) then

			end
		else
			superGroup:insert(obj)
		end
	end
end


local function addTap(target)
	if not coreDisplay.isDisplayObj(target) then
		return
	end
	target:addEventListener(
			"tap",
			function(event)
				eventDispatcher:dispatchEvent("chooseObj", {target = event.target})
				return true
			end
	)
	target:addEventListener(
			"touch",
			function(event)
				return true
			end
	)
end


function M.overWriteDisplay(superGroup)
	local oldDisplay = apiMgr.getOrigApi("display")
	local metaTable = {
		__index = function(t, key)
			local func = oldDisplay[key]

			local newFunc = func

			if type(func) == "function" then
				newFunc = function(...)
					local tParams = {...}

					local obj = func(...)

					changeParent(obj, tParams[1], superGroup)
					addTap(obj)


					return obj


				end
			end
			t[key] = newFunc

			return newFunc
		end
	}
	display = setmetatable({}, metaTable)
end

return M